package com.warehouse.module.business.controller.admin.cargoplan.convert;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.warehouse.framework.common.util.date.DateUtils;

import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author liutao
 * @version 1.0
 * @description: 将时间格式转化为yyyy-MM-dd
 * @date 2024/8/21 12:51
 */
public class DateConverter implements Converter<Date> {

    @Override
    public Class<Date> supportJavaTypeKey() {
        return Date.class;
    }
 
 
    @Override
    public WriteCellData<String> convertToExcelData(WriteConverterContext<Date> context) throws Exception {
        Date date = context.getValue();
        if (date == null) {
            return null;
        }
        return new WriteCellData<>(DateUtil.format(date, DatePattern.NORM_DATE_PATTERN));
    }
}